<?php
	require_once("../includes/user.php");
	$db=new User();
	$q_res=$db->query("select * from quiz_names where quiz_id ='$_POST[q_id]' ");
	$q_row=mysql_fetch_array($q_res);
 ?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td height="35"><div id="add_quiz_status" class="strykerNotice"></div></td>
  </tr>
</table>
<table width="444" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="444"><div class="Innerheading" id="Innerheading">Edit Quiz</div></td>
  </tr>
  <tr>
    <td>
    <div class="InnerDarkbox" id="InnerDarkbox">
    <table id="add_quiz_table"  width="443" height="149" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>
        <td width="148" height="22" align="right" valign="top">Quiz Name :</td>
        <td height="10" colspan="2" align="left" valign="top"><input name="quiz_name" type="text" class="FormTextFeild" id="quiz_name" value="<?php echo $q_row['quiz_name']; ?>" />  </td>
      </tr>
      <tr>
        <td width="148" height="19" align="right" valign="top">Quiz Active From :</td>
        <td height="10" colspan="2" align="left" valign="top">
          <input name="start_date" type="text" class="FormTextFeild" id="start_date" onFocus="popcal('st_dt_cal','start_date')" value="<?php 
		  $f_date=explode('-',$q_row['from_date']);
		  echo $f_date[2].'/'.$f_date[1].'/'.$f_date[0];
		   ?>" /> <div id ="st_dt_cal"  style="position:absolute; z-index:1000" ></div>       </td>
      </tr>
      <tr>
        <td width="148" align="right" valign="top">Quiz Active Till :</td>
        <td colspan="2" align="left" valign="top">
          <input name="end_date" type="text" class="FormTextFeild" id="end_date" onFocus="popcal('en_dt_cal','end_date')" value="<?php 
		  $e_date=explode('-',$q_row['to_date']);
		  echo $e_date[2].'/'.$e_date[1].'/'.$e_date[0];
		   ?>"  /> <div id ="en_dt_cal"  style="position:absolute; z-index:100" ></div></td>
      </tr>
      <tr>
        <td width="148" align="right" valign="top">Duration :</td>
        <td colspan="2" >
         <input name="Duration"  type="radio" id="no_limit" <?php if($q_row['duration']=='Nill'){
		  echo 'checked="checked"'; 
		  }
		  ?> onclick="remove_time_limit()"  />
          No limit
            <input name="Duration" type="radio" id="limit" <?php if($q_row['duration']!='Nill'){
			echo 'checked="checked"'; 
			} ?> onclick="add_time_limit()"  />
              Time limit
            <div id="time_limit" <?php if($q_row['duration']=='Nill') { ?>style="display:none;" <?php } ?>>
            <?php if($q_row['duration']!='Nill'){
					$tim=explode(':',$q_row['duration']);
			}  ?>
              <select name="hour" id="hour">
                <?php for($i=0;$i<=24;$i++)
				{
					if($tim[0]==$i)
					{
						echo "<option value='$i' selected='selected' >$i</option>";
					}
					else
					{
						echo "<option value='$i'>$i</option>";
					}
				}
				?>
              </select>
              <strong>:</strong>
              <select name="minutes" id="minutes">
                <?php for($i=0;$i<60;$i++)
				{
					if($tim[1]==$i)
					{
						echo "<option value='$i' selected='selected' >$i</option>";
					}
					else
					{
						echo "<option value='$i'>$i</option>";
					}
				}
				?>
              </select>
              <strong> :</strong>
              <select name="seconds" id="seconds">
                <?php for($i=0;$i<60;$i++)
				{
					if($tim[2]==$i)
					{
						echo "<option value='$i' selected='selected' >$i</option>";
					}
					else
					{
						echo "<option value='$i'>$i</option>";
					}
				}
				?>              </select>
          </div>
          <div id="time_limit_msg" class="disp" ></div>
          </td>
      </tr>
      <tr>
        <td width="148" align="right" valign="top">Questions Type :</td>
        <td colspan="2" valign="top"><select name="select_quiz_type" class="FormTextFeild" id="select_quiz_type">
            <?php
	  $quiz_types_res=$db->query("select * from quiz_types");
	  while($quiz_types_row=mysql_fetch_array($quiz_types_res))
	  {
	  	if($quiz_types_row['id']==$q_row['quiz_type'])
		{
echo "<option value= '$quiz_types_row[id]' selected='selected' >$quiz_types_row[type]</option>";
		}
		else
		{
			echo "<option value=$quiz_types_row[id]>$quiz_types_row[type]</option>";
		}
	  }
		?>
        </select></td>
      </tr>
      <tr>
        <td width="148" align="right" valign="middle">No of Questions :</td>
        <td width="156" valign="middle">
          <select name="no_of_ques" class="FormTextFeild" id="no_of_ques">
 <option value="5" <?php if($q_row['no_of_ques']==5)echo "selected='selected'"; ?> >5</option>
 <option value="10" <?php if($q_row['no_of_ques']==10)echo "selected='selected'"; ?> >10</option>
 <option value="15" <?php if($q_row['no_of_ques']==15)echo "selected='selected'"; ?> >15</option>
 <option value="20" <?php if($q_row['no_of_ques']==20)echo "selected='selected'"; ?> >20</option>
 <option value="25" <?php if($q_row['no_of_ques']==25)echo "selected='selected'"; ?> >25</option>
 <option value="50" <?php if($q_row['no_of_ques']==50)echo "selected='selected'"; ?> >50</option>
 <option value="0" <?php if(!($q_row['no_of_ques']==5 || $q_row['no_of_ques']==10 || $q_row['no_of_ques']==15||$q_row['no_of_ques']==20||$q_row['no_of_ques']==25 || $q_row['no_of_ques']==50)){echo "selected='selected'"; } ?> >As defined :</option>
          </select>
        </td>
        <td width="139" height="30" align="left" valign="middle"><input name="numbers" type="text" id="numbers" 
		<?php if($q_row['no_of_ques']==5 || $q_row['no_of_ques']==10 || $q_row['no_of_ques']==15||$q_row['no_of_ques']==20||$q_row['no_of_ques']==25 || $q_row['no_of_ques']==50)
		{ ?> style="width: 70px; display:none;"<?php }else{ ?> value="<?php echo $q_row['no_of_ques'];  ?>" <?php }?>/></td>
      </tr>
      <tr>
        <td width="148" align="right" valign="top">Answer's Review :</td>
        <td colspan="2" >
          <input name="review_answers" type="checkbox" id="review_answers" value="1" <?php if($q_row['review']==1) echo 'checked'; ?> />
        </td>
      </tr>
      <tr>
        <td width="148" align="right" valign="top">Quiz for :</td>
        <td colspan="2">
          <select name="quiz_for" class="FormTextFeild" id="quiz_for">
            <option value="0" selected="selected">All Students</option>
            <?php
		 	$year_res=$db->query("select * from year_details where visibility=1");
	  		while($year_row=mysql_fetch_array($year_res))
	  		{
				if($q_row['year_id']==$year_row['year_id'])
				{
echo "<option value=$year_row[year_id] selected='selected' >$year_row[year_name] Only</option>";
				}
				else
				{
					echo "<option value=$year_row[year_id]>$year_row[year_name] Only</option>";
				}
	  		}
		  ?>
          </select>
        </td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td width="148" align="right">&nbsp;</td>
        <td colspan="2">	
<input type="image" name="next" id="next" src="img/buttons/next.gif" onclick="update_edit_quiz(<?php echo $q_row['quiz_id']; ?>)" />
   </td>
      </tr>
    </table>
    </div>
    </td>
  </tr>
</table>
<script>
	$('#add_quiz_table').ready(function(){
		$('#add_quiz_status').html('Please fill the fields carefully').show().fadeOut(3000);
	});
	$('#start_date').keypress(function(e){
		if( e.which!=8 && e.which!=0 && e.which!=47 && (e.which<48 || e.which>57))
		{
			return false;
		}
	});
	$('#numbers').keypress(function(e){
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
		{
			return false;
		}
	});
	$('#end_date').keypress(function(e){
		if( e.which!=8 && e.which!=0 && e.which!=47 && (e.which<48 || e.which>57))
		{
			return false;
		}
	});
	$('#hour').change(function(){
		$('#time_limit_msg').html($('#hour').val()+' hours : '+$('#minutes').val()+' minutes : '+$('#seconds').val()+' seconds').show();
	});
	$('#minutes').change(function(){
		$('#time_limit_msg').html($('#hour').val()+' hours : '+$('#minutes').val()+' minutes : '+$('#seconds').val()+' seconds').show();
	});
	$('#seconds').change(function(){
		$('#time_limit_msg').html($('#hour').val()+' hours : '+$('#minutes').val()+' minutes : '+$('#seconds').val()+' seconds').show();
	});
	$('#review_answers').click(function(){
	$('#add_quiz_status').addClass('strykerNotice');
	if($('#review_answers').is(':checked'))
		{
			$('#add_quiz_status').addClass('strykerNotice');
			$('#add_quiz_status').html('User can verify his answers after completion of quiz').show().fadeOut(5000);
		}
		else
		{
			$('#add_quiz_status').html('User cannot verify his answers after completion of quiz').show().fadeOut(5000);
		}
	});
	$('#no_of_ques').change(function(){
		if($('#no_of_ques').val()==0)
		{
			$('#numbers').show();
		}
		else
		{
			$('#numbers').hide();
		}
	});
</script>